package com.fivestar.pmanager.service;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fivestar.pmanager.core.base.BaseCommonParameterBean;
import com.fivestar.pmanager.core.exception.DMLNoRecordEffectedException;
import com.fivestar.pmanager.core.service.BaseServiceImpl;
import com.fivestar.pmanager.dao.mapper.SysRoleMapper;
import com.fivestar.pmanager.model.SysRoleBean;

 /**
 * 角色
 * SysRoleService
 * @author 
 */
@Service("sysRoleService")
public class SysRoleService extends BaseServiceImpl<SysRoleBean>
{
	private final static Logger log = Logger.getLogger(SysRoleService.class);
	@Autowired
    private SysRoleMapper mapper;


    @Override
    public int insert(SysRoleBean sysRole, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	sysRole.initBeforeCreate(commonParam.getActorId());
        int result;
        if ((result = mapper.insert(sysRole)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public int delete(SysRoleBean sysRole, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	sysRole.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.delete(sysRole)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }

    @Override
    public int deletePhysics(SysRoleBean sysRole, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException {
        int result;
        if ((result = mapper.deletePhysics(sysRole)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public int update(SysRoleBean sysRole, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	sysRole.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.update(sysRole)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }
    
    
    @Override
    public int updateBySelective(SysRoleBean sysRole, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
    	sysRole.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.updateBySelective(sysRole)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public List<SysRoleBean> getList(SysRoleBean sysRole)
    {
        return mapper.getList(sysRole);
    }


    @Override
    public SysRoleBean getSingleById(Integer id)
    {
        return mapper.getSingleById(id);
    }


    @Override
    public int getCountOfPage(SysRoleBean sysRole)
    {
        return mapper.getCountOfPage(sysRole);
    }


    @Override
    public List<SysRoleBean> getListOfPage(SysRoleBean sysRole)
    {
        return mapper.getListOfPage(sysRole);
    }


	@Override
    public int getCount(SysRoleBean sysRole)
    {
        return mapper.getCount(sysRole);
    }


    @Override
    public void save(SysRoleBean sysRole, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        if(sysRole.getRowId() == null)
        {
            insert(sysRole, commonParam);
        }
        else
        {
            updateBySelective(sysRole, commonParam);
        }
    }


    @Override
    public SysRoleBean getSingle(SysRoleBean sysRole)
    {
        return mapper.getSingle(sysRole);
    }


    /**
     * 根据关键字查询
     *
     * @param keyWord 关键字
     * @return
     */
    public List<Map<String,Object>> findByKeyWord(String keyWord)
    {
        return mapper.findByKeyWord(keyWord);
    }

}
